<template>
<view class="container">
    <!--轮播图-->
    <view class="header">
        <image :src="imgUrl+banner"></image>
    </view>
    <view class="line">
        
    </view>
    <view class="page-section-spacing">
        <scroll-view class="scroll-view_H" scroll-x="true" bindscroll="scroll" style="width: 100%">
          <view v-for="(item,index) in cate" @click="select(item.id,index)" :key="index" class="scroll-view-item_H"
		  :class="{checktrue : key == index}"
		  >{{item.name}}</view>
        </scroll-view>
     </view>
    <view class="body">
        <view class="newslist" v-for="(item,index) in course" :key="index" @click="jump(item.id)">
            <image :src="imgUrl+item.img"></image>
        </view>
    </view>
</view>
</template>
<script>
import request from '@/util/request.js'	
export default {
	data() {
		return {
			imgUrl:this.url,
			banner:'',
			cate:[],
			key:0,
			schoolId:0,
			totalPage:0,
			page:1,
			course:[]
		}
	},
	onLoad:function(e){
		uni.showLoading({
		    title: '加载中'  
		});
		this.schoolId = e.id
		this.getBanner()
		this.getCate()
	},
	methods: {
		getBanner:function(){
			var that = this;
			var data = {'type':3}
			request({
				url: 'banner',
				method: 'get',
				data:data,
				success: (res) => {
					that.banner = res.data.data[0].img
				}
			})
		},
		getCate:function(){
			var that = this
			request({
				url: 'course/cate',
				method: 'get',
				success: (res) => {
					that.cate = res.data.data
					that.cateId = res.data.data[0]['id']
					that.getCourse()
				}
			})
		},
		getCourse:function(){
			var that = this
			var data = {
				schoolId:this.schoolId,
				cateId:this.cateId,
				page:this.page,
			}
			request({
				url: 'course/list',
				method: 'get',
				data:data,
				success: (res) => {
					if(res.data.code == 1){
						uni.hideLoading()
						if(that.totalPage == 0){
							that.totalPage = res.data.data.last_page
						}
						if(that.page == 1){
							that.course = res.data.data.data
						}else{
							var course = that.course
							that.course = course.concat(res.data.data.data)
						}
					}
				}
			})
		},
		select:function(id,index){
			this.key = index
			this.cateId = id
			this.page = 1
			this.totalPage = 0
			uni.showLoading({
			    title: '加载中'  
			});
			this.getCourse()
		},
		onReachBottom: function(){
			if(this.page < this.totalPage){
				//当前不是最后一页可加载
				this.page = this.page + 1
				uni.showLoading({
				    title: '加载中'  
				});
				this.getCourse();
			}
		},
		jump:function(id){
			uni.navigateTo({
				url:'/pages/course/info?id='+id
			});
		}
	}
}
</script>
<style scoped>
	@import url("./list.css");
</style>